//
//  exSyncAppDelegate.m
//  exSync
//
//  Created by Alexander Chaika on 23.01.12.
//  Copyright 2012 by Alexander Chaika. All rights reserved.
//

#import "resource.h"

#import "Synchronization.h"
#import "exSyncAppDelegate.h"

@implementation exSyncAppDelegate

+ (void)initialize {
	// set up factory defaults for preferences
    NSDictionary *defaults = [NSDictionary dictionaryWithObjectsAndKeys:
							  [NSNumber numberWithBool:NO], kSyncStarted,
							  [NSNumber numberWithBool:NO], kSyncContacts,
							  [NSNumber numberWithBool:NO], kSyncCalendars,
							  [NSNumber numberWithInt:-1], kSyncSchedule, // manual sync
							  nil];
    [[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
	[sync start]; // try to start synchronization processes
}

- (void)applicationWillTerminate:(NSNotification *)aNotification {
	[sync stop]; // gently stop synchronization processes
}

- (void)awakeFromNib {
	// Take status bar item and attach mein menu to it.
	statusItem = [[[NSStatusBar systemStatusBar]
				   statusItemWithLength:NSVariableStatusItemLength]
				  retain];
	[statusItem setMenu:statusMenu];
	[statusItem setTitle:@"exSync"]; // FIXME: Later we should make an beautiful icon...
	[statusItem setHighlightMode:YES];
}

- (IBAction)showPreferences:(id)sender {
	[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
	[preferencesWindow makeKeyAndOrderFront:sender];
}

- (void)dealloc {
	[statusItem release];
    [super dealloc];
}

@end
